package game.module.mj.logic;

import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import game.module.mj.bean.MjRound;

public class MjDataManager {

	private static Logger logger = LoggerFactory.getLogger(MjDataManager.class);

	static class SingletonHolder {
		static MjDataManager instance = new MjDataManager();
	}

	public static MjDataManager getInstance() {
		return SingletonHolder.instance;
	}

	private Cache<Integer, MjRound> roundCache = CacheBuilder.newBuilder().concurrencyLevel(8)
			.expireAfterAccess(2, TimeUnit.HOURS).build();

	public void addRoundCache(int playerId, MjRound mjRound) {
		roundCache.put(playerId, mjRound);
	}

	public MjRound getMjRoom(int playerId) {
		return roundCache.getIfPresent(playerId);
	}

	public void removePlayer(int playerId) {
		roundCache.invalidate(playerId);
	}

	public int getPlayerCount() {
		int countSum = (int) roundCache.size();
		return countSum;
	}

}
